//
//  NetworkTool.m
//  QFBAPP
//
//  Created by 无常先生 on 2018/4/30.
//  Copyright © 2018年 YIXun. All rights reserved.
//

#import "NetworkTool.h"
#import "ApiSeriver.h"

//#import "QFBPublicMacroHeader.h"
//#import "NSObject+QFBHUD.h"

//static NSString * const baseURL = @"http://m.dev.qiaofangyun.com/";
@implementation NetworkTool


#pragma mark - 类初始化方法
+ (instancetype)sharedManager{
    static NetworkTool *sharedNetworkSingleton = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate,^{
    
        ApiSeriver *apiServer = [[ApiSeriver alloc] init];
//        [apiServer setServerUrl:apiBaseUrl forServerType:ApiServerTypeAlpha];
        [apiServer setServerType:ApiServerTypeAlpha];
        [apiServer startMonitoring];
        
        sharedNetworkSingleton = [[NetworkTool alloc]initWithServer:apiServer];
    });
    return sharedNetworkSingleton;
}

- (AFHTTPRequestSerializer *)clientHTTPHeaderField {
    
    AFHTTPRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
    //header 设置
//    [serializer setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forHTTPHeaderField:@"appversion"];
//    [serializer setValue:X_AUTH_TOKEN forHTTPHeaderField:@"X-AUTH-TOKEN"];
//    [serializer setValue:QFBUUID forHTTPHeaderField:@"X-AUTH-OPENID"];
//    NSLog(@"QFBUUID = %@",QFBUUID);
//    [serializer setValue:@"iOS" forHTTPHeaderField:@"X-AUTH-DEVICETYPE"];
//    [serializer setValue:[NSString stringWithFormat:@"QiaofangApp/com.QFZS.Qiaofang.app (%@; OS Version %f)", APP_Build, IOS_VERSION] forHTTPHeaderField:@"User-Agent"];
//    [serializer setValue:COMPANY_CODE forHTTPHeaderField:@"CompanyCode"];
//    NSLog(@"QFBUUID = %@",QFBUUID);
//    [serializer setValue:@"application/json;charset=utf8" forHTTPHeaderField:@"Content-Type"];
//    [serializer setTimeoutInterval:60];

    return  serializer;
}

- (void)requestErrorWithErrorCode:(NSError *)error {

//    //发送接口报错信息
//    if (!IS_DEFBUG) {
//        [AppAnalytics sendError:error];
//    }
//    NSString *errorTitle = nil;
//    if (error.code == -1001) {
//        [self showText:@"访问超时请重新加载！"];
//        errorTitle = @"访问超时请重新加载！";
//    }else if (error.code == -1009) {
//        [self showText:@"似乎已断开与互联网的连接！"];
//        errorTitle = @"似乎已断开与互联网的连接！";
//    }else if (error.code == -1011) {
//        [self showText:@"连接服务器失败，请联系客服"];
//        errorTitle = @"连接服务器失败，请联系客服";
//    }else if (error.code == -1004) {
//        [self showText:@"未能连接到服务器,请联系客服"];
//        errorTitle = @"未能连接到服务器,请联系客服";
//    }else if (error.code == -999) { // 取消的网络请求
//    }else {
//        [self showText:@"糟糕！网络不给力"];
//        errorTitle = @"糟糕！网络不给力";
//    }
//    [QFBDEF setObject:errorTitle forKey:@"errorTitle"];
//    [self dismissLoadingDelay:2];
  
}
@end
